package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.HomeService;
import com.yoda.mall.admin.service.ProductService;
import com.yoda.mall.admin.service.SubjectService;
import com.yoda.mall.model.dto.HomeBrandDto;
import com.yoda.mall.model.dto.HomeProductDto;
import com.yoda.mall.model.dto.SubjectDto;
import com.yoda.mall.model.entity.sms.HomeBrand;
import com.yoda.mall.model.entity.sms.HomeNewProduct;
import com.yoda.mall.model.entity.sms.HomeRecommendProduct;
import com.yoda.mall.model.entity.sms.HomeRecommendSubject;
import com.yoda.mall.model.vo.PageResult;
import com.yoda.mall.model.vo.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author shawn
 * @date 2022年 12月 16日 14:40
 */
@RestController
@RequestMapping("/home")
public class HomeController {

    @Resource
    private HomeService homeService;

    @Resource
    private ProductService productService;

    @Resource
    private SubjectService subjectService;

/**=========================================================================================
======================================专题推荐模块============================================
============================================================================================**/

    @PostMapping("/recommendSubject/create")
    public R createRecommendSubject(@RequestBody List<SubjectDto> homeSubjectList) {
        //调用service处理前端传递过来的数据
        Integer count = subjectService.createRecommendSubject(homeSubjectList);
        //返回
        return R.success(count);
    }

    /**
     * 根据id批量删除
     *
     * @param ids             id
     * @return {@link R}
     */
    @PostMapping("/recommendSubject/delete")
    public R deleteRecommendSubjectByIds(@RequestParam List<Long> ids){
        homeService.deleteRecommendSubjectByIds(ids);
        return R.success();
    }

    /**
     * 批量更新推荐商品推荐状态
     *
     * @param ids             id
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @PostMapping("/recommendSubject/update/recommendStatus")
    public R updateRecommendSubjectStatus(@RequestParam List<Long> ids,@RequestParam Integer recommendStatus){
        homeService.updateRecommendSubjectStatus(ids,recommendStatus);
        return R.success();
    }

    /**
     * 改变推荐产品排序
     *
     * @param id   id
     * @param sort 排序
     * @return {@link R}
     */
    @PostMapping("/recommendSubject/update/sort/{id}")
    public R changeRecommendSubjectSort(@PathVariable Long id,Integer sort){
        homeService.changeRecommendSubjectSort(id,sort);
        return R.success();
    }

    /**
     * 分页获取推荐产品
     *
     * @param pageNum         页面num
     * @param pageSize        页面大小
     * @param subjectName     专题名称
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @GetMapping("/recommendSubject/list")
    public R getRecommendSubjectPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            String subjectName,Integer recommendStatus){
        PageResult<HomeRecommendSubject> pageResult = homeService.getRecommendSubjectPage(pageNum,pageSize,subjectName,recommendStatus);
        return R.success(pageResult);
    }
/**=========================================================================================
 ======================================人气商品模块============================================
 ============================================================================================**/
    @PostMapping("/recommendProduct/create")
    public R createRecommendProduct(@RequestBody List<HomeProductDto> homeProductList) {
        //调用service处理前端传递过来的数据
        Integer count = productService.createRecommendProduct(homeProductList);
        //返回
        return R.success(count);
    }

    /**
     * 根据id批量删除
     *
     * @param ids             id
     * @return {@link R}
     */
    @PostMapping("/recommendProduct/delete")
    public R deleteRecommendProductByIds(@RequestParam List<Long> ids){
        homeService.deleteRecommendProductByIds(ids);
        return R.success();
    }

    /**
     * 批量更新推荐商品推荐状态
     *
     * @param ids             id
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @PostMapping("/recommendProduct/update/recommendStatus")
    public R updateRecommendProductStatus(@RequestParam List<Long> ids,@RequestParam Integer recommendStatus){
        homeService.updateRecommendProductStatus(ids,recommendStatus);
        return R.success();
    }

    /**
     * 改变推荐产品排序
     *
     * @param id   id
     * @param sort 排序
     * @return {@link R}
     */
    @PostMapping("/recommendProduct/update/sort/{id}")
    public R changeRecommendProductSort(@PathVariable Long id,Integer sort){
        homeService.changeRecommendProductSort(id,sort);
        return R.success();
    }

    /**
     * 分页获取推荐产品
     *
     * @param pageNum         页面num
     * @param pageSize        页面大小
     * @param productName     产品名称
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @GetMapping("/recommendProduct/list")
    public R getRecommendProductPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            String productName,Integer recommendStatus){
        PageResult<HomeRecommendProduct> pageResult = homeService.getHomeRecommendProductPage(pageNum,pageSize,productName,recommendStatus);
        return R.success(pageResult);
    }

/**=========================================================================================
 ======================================新品推荐模块============================================
 ============================================================================================**/
    @PostMapping("/newProduct/create")
    public R createNewProduct(@RequestBody List<HomeProductDto> homeProductList) {
        //调用service处理前端传递过来的数据
        Integer count = productService.createNewProduct(homeProductList);
        //返回
        return R.success(count);
    }

    /**
     * 分页获取新产品
     *
     * @param pageNum         页面num
     * @param pageSize        页面大小
     * @param productName     产品名称
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @GetMapping("/newProduct/list")
    public R getNewProductPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            String productName,Integer recommendStatus){
      PageResult<HomeNewProduct> pageResult = homeService.getNewProductPage(pageNum,pageSize,productName,recommendStatus);
      return R.success(pageResult);
    }

    /**
     * 改变新产品排序
     *
     * @param id   id
     * @param sort 排序
     * @return {@link R}
     */
    @PostMapping("/newProduct/update/sort/{id}")
    public R changeNewProductSort(@PathVariable Long id,Integer sort){
        homeService.changeNewProductSort(id,sort);
        return R.success();
    }

    /**
     * 批量更新新品推荐状态
     *
     * @param ids             id
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @PostMapping("/newProduct/update/recommendStatus")
    public R updateNewProductStatus(@RequestParam List<Long> ids,@RequestParam Integer recommendStatus){
        homeService.updateNewProductStatus(ids,recommendStatus);
        return R.success();
    }

    /**
     * 根据id批量删除
     *
     * @param ids             id
     * @return {@link R}
     */
    @PostMapping("/newProduct/delete")
    public R deleteNewProductByIds(@RequestParam List<Long> ids){
        homeService.deleteNewProductByIds(ids);
        return R.success();
    }

/**=========================================================================================
 ======================================品牌推荐模块============================================
 ============================================================================================**/

    /**
     * 批量改变品牌排序
     *
     * @param id   id
     * @param sort 排序
     * @return {@link R}
     */
    @PostMapping("brand/update/sort/{id}")
    public R changeBrandSort(@PathVariable Long id,Integer sort){
        homeService.changeBrandSort(id,sort);
        return R.success();
    }

    /**
     * 批量更新推荐状态
     *
     * @param ids             id
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @PostMapping("/brand/update/recommendStatus")
    public R updateRecommendStatus(@RequestParam List<Long> ids,@RequestParam Integer recommendStatus){
        homeService.updateHomeBrandById(ids,recommendStatus);
        return R.success();
    }

    /**
     * 根据id批量删除
     *
     * @param ids             id
     * @return {@link R}
     */
    @PostMapping("/brand/delete")
    public R deleteByIds(@RequestParam List<Long> ids){
        homeService.deleteByIds(ids);
        return R.success();
    }

    /**
     * 分页查询推荐品牌
     *
     * @param pageNum         页面num
     * @param pageSize        页面大小
     * @param brandName       品牌名称
     * @param recommendStatus 推荐状态
     * @return {@link R}
     */
    @GetMapping("/brand/list")//?pageNum=1&pageSize=5&brandName=aaa&recommendStatus=0
    public R getRecommendBrands(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            String brandName,Integer recommendStatus){
        PageResult<HomeBrand> pageResult = homeService.getRecommendBrands(pageNum,pageSize,brandName,recommendStatus);
        return R.success(pageResult);
    }

    /**
     * 创建推荐品牌
     *
     * @param homeBrandList 首页品牌列表
     * @return {@link R}
     */
    @PostMapping("/brand/create")
    public R createRecommendBrand(@RequestBody List<HomeBrandDto> homeBrandList){
        Integer count = homeService.createRecommendBrand(homeBrandList);
        return R.success(count);
    }
}
